﻿@using System.Windows.Input
@namespace BlazorFluentUI.Routing

@if (Items == null)
{
    <NavLink Name=@Name
                Url=@Url
                NavMatchType=@NavMatchType
                Id=@Id
                NestedDepth=@NestedDepth
                IconName=@IconName
                IconSrc=@IconSrc
                @bind-IsExpanded=@IsExpanded
                Command=@Command
                CommandParameter=@CommandParameter/>
}
else
{
    <NavLink Name=@Name
                Url=@Url
                NavMatchType=@NavMatchType
                Id=@Id
                NestedDepth=@NestedDepth
                IconName=@IconName
                IconSrc=@IconSrc
                @bind-IsExpanded=@IsExpanded
                Command=@Command
                CommandParameter=@CommandParameter>
        @foreach (INavBarItem subItem in Items)
        {
            <RecursiveNavLink Name=@subItem.Text
                                 Url=@subItem.Url
                                 NavMatchType=@subItem.NavMatchType
                                 Id=@subItem.Id
                                 NestedDepth=@(NestedDepth + 1)
                                 IconName=@subItem.IconName
                                 IconSrc=@subItem.IconSrc
                                 Items=@subItem.Items
                                 @bind-IsExpanded=@subItem.IsExpanded
                                 Command=@subItem.Command
                                 CommandParameter=@subItem.CommandParameter/>
        }
    </NavLink>
}
@code{

    [Parameter] public IEnumerable<IContextualMenuItem>? Items { get; set; }  //LINKS

    [Parameter] public bool Disabled { get; set; }
    [Parameter] public bool ForceAnchor { get; set; } //unused for now
    [Parameter] public string? IconName { get; set; }
    [Parameter] public string? IconSrc { get; set; }
    [Parameter] public bool IsButton { get; set; }
    [Parameter] public bool IsExpanded { get; set; }
    [Parameter] public EventCallback<bool> IsExpandedChanged { get; set; }
    [Parameter] public string? Name { get; set; }
    [Parameter] public string? Target { get; set; }  //link <a> target
    [Parameter] public string? Title { get; set; } //tooltip and ARIA
    [Parameter] public string? Id { get; set; }
    [Parameter] public string? Url { get; set; }
    [Parameter] public int NestedDepth { get; set; } = 0;
    [Parameter] public NavMatchType NavMatchType { get; set; } = NavMatchType.RelativeLinkOnly;
    [Parameter] public EventCallback<NavLink> OnClick { get; set; }
    [Parameter] public ICommand? Command { get; set; }
    [Parameter] public object? CommandParameter { get; set; }

}